<?
error_reporting(E_ALL); ini_set('display_errors', '1');
session_start();
if(!isset($_SESSION["ftpuserinfo"]) && isset($_REQUEST["fi"])) {
   $_SESSION["ftpuserinfo"] = $_REQUEST["fi"];
}
$svr = $_SESSION["ftpuserinfo"];
$path = $_REQUEST["path"];

switch($_REQUEST["f"]) {
	case 'dir':
     $f = file_get_contents("ftp://$svr$path");     
	  preg_match_all('/\S+$/ims', $f, $m);
     var_dump($m[0]);
	  break;
	 case 'get':
     $fn = basename($path);
     header ("Content-Disposition:attachment; filename=\"$fn\"");
     readfile(	"ftp://$svr$path");
	  break;
	 case 'put':
	    $stream = stream_context_create(array('ftp' => array('overwrite' => true))); 
       file_put_contents("ftp://$svr$path", "php://input", 0, $stream); 
       break;	  
}

?>